/*
 * Platzad
 * Copyright 2008 Shayne Riley
 *
 * This file is part of Platzad.
 *
 * Platzad is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Platzad is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Platzad.  If not, see <http://www.gnu.org/licenses/>.
 *
 * To contact the authors on questions or issues regarding the license,
 * you may send an email to <shayner at gmail dot com> or write to
 * Shayne Riley / P.O. Box 1092 / McCook, NE 69001.
 */

#include "Display.h"
#include <SDL/SDL.h>
#include <iostream>

namespace pzdDisplay
{

Display::Display()
: gfx(getGraphics()),
  mBack(NULL),
  mActor(NULL),
  mActorPosX(296),
  mActorPosY(233)
{
}

Display::~Display()
{
}

Graphics& Display::getGraphics()
{
	return Graphics::getInstance();
}

void Display::doFrame()
{
	if(mBack != NULL)
	{
		gfx.drawImage(mBack, 0, 0, 640, 480);
	}
	if(mActor != NULL)
	{
		gfx.drawImage(mActor, mActorPosX, mActorPosY);
	}
	gfx.renderScene();
}

void Display::setBackground(const ImageSDL * const back)
{
	mBack = back;
}

void Display::setActor(const ImageSDL * const actor)
{
	mActor = actor;

	Uint32 colorkey = SDL_MapRGB(mActor->getSurface()->format, 255, 128, 255);
	SDL_SetColorKey(mActor->getSurface(), SDL_SRCCOLORKEY, colorkey);
}

void Display::setActorPos(int posX, int posY)
{
	mActorPosX = posX;
	mActorPosY = posY;
}

} // namespace
